#ifndef __STAIRS_BLOCK_H__
#define __STAIRS_BLOCK_H__

#include "Block.hpp"
#include "IPaintableBlock.hpp"


using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
	enum class CornerType
	{
		None,
		OneQuarter,
		ThreeQuarters
	};
    
    // 楼梯方块
    class StairsBlock : public Block, public IPaintableBlock
    {
    public:
        StairsBlock();
        virtual void getCreativeValues(std::vector<int32_t> &blockVec) override;
        virtual void getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues) override;
        virtual bool isFaceTransparent(int32_t face, int32_t value) override;
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;
        virtual const std::vector<BoundingBox> &getCustomCollisionBoxes(int32_t value) override;

        virtual int32_t getPaintColor(int32_t value) override;
        virtual int32_t paint(int32_t value, int32_t color) override;

        static inline Point3 RotationToDirection(int32_t rotation);
        static inline int32_t GetRotation(int32_t data);
		static inline int32_t SetRotation(int32_t data, int32_t rotation);
		static inline bool GetIsUpsideDown(int32_t data);
        static inline int32_t SetIsUpsideDown(int32_t data, bool isUpsideDown);
		static inline CornerType GetCornerType(int32_t data);
		static inline int32_t SetCornerType(int32_t data, CornerType cornerType);
        
        static inline int32_t GetColor(int32_t data);
        static inline int32_t SetColor(int32_t data, int32_t color);
		static inline int32_t GetVariant(int32_t data);

    };
    inline Point3 StairsBlock::RotationToDirection(int32_t rotation)
    {
        return CellFace::FaceToPoint3((rotation + 2) % 4);
    }
    inline int32_t StairsBlock::GetRotation(int32_t data)
    {
        return data & 3;
    }
	inline int32_t StairsBlock::SetRotation(int32_t data, int32_t rotation)
	{
		return (data & -4) | (rotation & 3);
	}
	inline bool StairsBlock::GetIsUpsideDown(int32_t data)
	{
		return (data & 4) != 0;
	}
    inline int32_t StairsBlock::SetIsUpsideDown(int32_t data, bool isUpsideDown)
    {
        if(isUpsideDown)
        {
            return data | 4;
        }
        return data & -5;
    }
	inline CornerType StairsBlock::GetCornerType(int32_t data)
	{
		return (CornerType)((data >> 3) & 3);
	}

	inline int32_t StairsBlock::SetCornerType(int32_t data, CornerType cornerType)
	{
		return (data & -25) | ((int32_t)((int32_t)cornerType & 3) << 3);
    }
    inline int32_t StairsBlock::GetColor(int32_t data)
    {
		if ((data & 0x20) != 0)
		{
			return (data >> 6) & 0xF;
		}
		return -1;
    }
    inline int32_t StairsBlock::SetColor(int32_t data, int32_t color)
    {
		if (color != -1)
		{
			return (data & -993) | 0x20 | ((color & 0xF) << 6);
		}
		return data & -993;
    }
	inline int32_t StairsBlock::GetVariant(int32_t data)
	{
		return data & 0x1F;
	}
} // namespace PocketSurvival


#endif
